//------------------------------

let OfficeManageData = [
  {
    id: 0,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://giProje45w4er",
    qqzt: "404",
    qqhs: "3ms",
  },
  {
    id: 1,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "httpfao/Team8Proje45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 2,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://gite45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 3,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://gitfao/je45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 4,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://giTeam8Proje45w4er",
    qqzt: "400",
    qqhs: "5ms",
  },
  {
    id: 5,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://gitfoje45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 6,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://giProje45w4er",
    qqzt: "404",
    qqhs: "3ms",
  },
  {
    id: 7,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "httpfao/Team8Proje45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 8,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://gite45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 9,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://gitfao/je45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 10,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://giTeam8Proje45w4er",
    qqzt: "400",
    qqhs: "5ms",
  },
  {
    id: 11,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://gitfoje45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 12,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://giProje45w4er",
    qqzt: "404",
    qqhs: "3ms",
  },
  {
    id: 13,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "httpfao/Team8Proje45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 14,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://gite45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 15,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://gitfao/je45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 16,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://giTeam8Proje45w4er",
    qqzt: "400",
    qqhs: "5ms",
  },
  {
    id: 17,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://gitfoje45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 18,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://giProje45w4er",
    qqzt: "404",
    qqhs: "3ms",
  },
  {
    id: 19,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "httpfao/Team8Proje45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 20,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://gite45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 21,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://gitfao/je45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 22,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://giTeam8Proje45w4er",
    qqzt: "400",
    qqhs: "5ms",
  },
  {
    id: 23,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://gitfoje45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 24,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://giProje45w4er",
    qqzt: "404",
    qqhs: "3ms",
  },
  {
    id: 25,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "httpfao/Team8Proje45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 26,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://gite45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 27,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://gitfao/je45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
  {
    id: 28,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://giTeam8Proje45w4er",
    qqzt: "400",
    qqhs: "5ms",
  },
  {
    id: 29,
    key: "2020-10-10 10:00:00",
    job: "get",
    jobNum: "https://gitfoje45w4er",
    qqzt: "200",
    qqhs: "4ms",
  },
]
let showListByData = []
let maxPage
let nowPage = 1
let modifyid
let perNum = 3
let cancelid
initialData()

function initialData() {
  nowPage = 1
  $("#gotoPageInput").val("")
  showPage(OfficeManageData)
  showListBy(OfficeManageData, 1, perNum)
}

function showList(data) {
  $("#OfficeManageList").html("")
  for (let i = 0; i < data.length; i++) {
    $("#OfficeManageList").append(`
        <tr>
            <td class="displayN" >${data[i].id}</td> 
            <td>${data[i].key}</td>  
            <td>${data[i].job}</td>  
            <td>${data[i].jobNum}</td>
             <td>${data[i].qqzt}</td>  
            <td>${data[i].qqhs}</td>   
          </tr>
        `)
  }
}
function showListBy(data, pageNum, perNum) {
  let startNum = (pageNum - 1) * perNum
  showListByData = data.slice(startNum, startNum + perNum)
  showList(showListByData)
  let leftNum = pageNum % 5
  if (leftNum == 0) {
    $(".page").eq(4).addClass("active").siblings().removeClass("active")
  } else {
    $(".page")
      .eq(leftNum - 1)
      .addClass("active")
      .siblings()
      .removeClass("active")
  }
  nowPage = pageNum
}

function showPage(data) {
  maxPage = Math.ceil(data.length / perNum)
  let intNum = parseInt(Math.ceil(nowPage / 5))
  intNum--
  intNum = intNum * 5
  $("#pagebox").html("")
  for (let i = intNum + 1; i < intNum + 6; i++) {
    if (i <= maxPage) {
      $("#pagebox").append(`<span class="page">${i}</span>`)
    } else {
      break
    }
  }
  $("#totalNum").html("")
  $("#totalNum").html(`共${maxPage}页`)
}

$("#pagebox").on("click", ".page", function () {
  showListBy(OfficeManageData, parseInt($(this).text()), perNum)
})
//-----------------上下页--------------------------
$("#pre").click(function () {
  if (nowPage > 1) {
    nowPage -= 1
    showPage(OfficeManageData)
    showListBy(OfficeManageData, nowPage, perNum)
  }
})
$("#next").click(function () {
  if (nowPage < maxPage) {
    nowPage += 1
    showPage(OfficeManageData)
    showListBy(OfficeManageData, nowPage, perNum)
  }
})

$("#pageChange").change(function () {
  let Num = $("#pageChange").val()
  if (Num == 0) {
    perNum = 3
    initialData()
  } else if (Num == 1) {
    perNum = 5
    initialData()
  } else if (Num == 2) {
    perNum = 10
    initialData()
  }
})
$("#goTo").click(function () {
  let num = parseInt($("#gotoPageInput").val())
  if (num > 0 && num <= maxPage) {
    nowPage = num
    showPage(OfficeManageData)
    showListBy(OfficeManageData, num, perNum)
  } else {
    alert("请在正确的页码范围内输入")
  }
})
